package system

import (
	"io/ioutil"
	"gopkg.in/yaml.v2"
)

type Configuration struct {
	app_name string `项目名称`
	DSN      string `yaml:"dsn"`
	LogPath  string `yaml:"log_path"`
	IcoPath  string `yaml:"ico_path"`
	Port     string `yaml:"port"`
	MongoHost string `yaml:"mongoHost"`
	MongoPort string `yaml:"mongoPort"`
	MongoDb string `yaml:"mongoDb"`
	MongoDsn string `yaml:"mongoDsn"`
	RedisAddr string `yaml:"redisAddr"`
	RedisPwd string `yaml:"redisPwd"`
}

var configuration *Configuration

func LoadConfiguration(path string) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}
	var config Configuration
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		return err
	}
	configuration = &config
	return err
}

func GetConfiguration() *Configuration  {
	return configuration
}